//
//  ViewController.m
//  大文件上传
//
//  Created by songhuipan on 16/5/31.
//  Copyright © 2016年 songhuipan. All rights reserved.
//

#import "ViewController.h"
#import <AFNetworking/AFNetworking.h>
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView = ({
        
        UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.backgroundColor = [UIColor redColor];
        UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"image.png"]];
        imageView.frame = CGRectMake(0, 0, 300, 300);
        tableView.tableHeaderView = imageView;

        tableView;
    });
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return nil;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self uploadData];
}
- (void)uploadData {
    NSLog(@"开始了");
    double start = CACurrentMediaTime();
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:@"http://localhost/PHP/upload/upload.php" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"2.zip" ofType:nil]];
//        NSData *data = [NSData dataWithContentsOfFile:@"/Users/songhuipan/Desktop/06-实用技术阶段-第15天(通用项目).zip"];
        [formData appendPartWithFileData:data name:@"userfile" fileName:@"world" mimeType:@"application/octet-stream"];
    } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"上传成功了%@",responseObject);
        NSLog(@"%lf",CACurrentMediaTime()-start);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"上传失败了%@",error);
    }];
    
}
@end










